package com.example.dogliving.columnmodle;

import com.example.dogliving.bean.ColumnBean;
import com.example.dogliving.interfaces.IViewPager;
import com.example.dogliving.utils.Constant;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by 张博文 on 2016/12/27.
 */

public class ColumnModle implements IColumnModle {
    //栏目分类解析
    @Override
    public void login(final OnLoadColumnListener loadColumnListener) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constant.Column_URL)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        IViewPager iViewPager = retrofit.create(IViewPager.class);
        Observable<ColumnBean> observable = iViewPager.getColumnBean();
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ColumnBean>() {
                    @Override
                    public void call(ColumnBean columnBean) {
                        loadColumnListener.onSucess(columnBean);
                    }
                });
    }
}
